package systeme;

import org.apache.log4j.Logger;

import ihm.Deplacement;
import ihm.IHM;
import ihm.IHMImpl;

import java.util.ArrayList;

import cab.Cab;
import cab.ICab;
import cabine.Cabine;
import cabine.ICabine;

/**
 * @author Ilyass
 * @version 1.0
 * @created 22-mars-2012 22:58:38
 */
public class Ascenseur implements IOrdonnanceur, Constants {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Ascenseur.class);

	private int mEtageCourant;
	private int mSens;
	private Etat mEtat;
	private ICab mCabine;
	private IHM mIhm;
	private ArrayList<Deplacement> mMonteelist;
	private ArrayList<Deplacement> mDescentelist;

	public Ascenseur() {
		logger.info("Intialisation de l'ascenseur");
		mEtat = new AttenteDemande(this, null);
		mMonteelist = new ArrayList<Deplacement>();
		mDescentelist = new ArrayList<Deplacement>();
		mCabine =  new Cab(NBR_ETAGES, DELAIS_PAS_ASC, HAUTEUR_ETAGE,
				DELAIS_ARRET_ETAGE);
		mIhm = new IHMImpl(NBR_ETAGES, HAUTEUR_ETAGE);
		mCabine.assignerOrdonnanceur(this);
		mIhm.assignerOrdonnanceur(this);
	}

	public Etat getEtat() {
		return mEtat;
	}

	public void setEtat(Etat pEtat) {
		mEtat = pEtat;
	}

	public ICab getCabine() {
		return mCabine;
	}

	public void setCabine(ICab pCabine) {
		mCabine = pCabine;
	}

	public IHM getIhm() {
		return mIhm;
	}

	public void setIhm(IHM pIhm) {
		mIhm = pIhm;
	}

	public int getEtageCourant() {
		return mEtageCourant;
	}

	public void setEtageCourant(int pEtageCourant) {
		mEtageCourant = pEtageCourant;
	}

	public ArrayList<Deplacement> getMonteelist() {
		return mMonteelist;
	}

	public ArrayList<Deplacement> getDescentelist() {
		return mDescentelist;
	}

	public int getSens() {
		return mSens;
	}

	public void maj(int pEtage, int pSens) {
		mEtageCourant = pEtage;
		mSens = pSens;
	}

	public void demander(Deplacement dep) {
		mEtat.demander(dep);
	}

	public void arretUrgence() {
		mEtat.arretUrgence();
	}

	public void signalerChangementDEtage() {
		mEtat.signalerChangementDEtage();
	}

	public static void main(String[] args) {
		new Ascenseur();
	}
}